package com.baizhi.controller;


import com.baizhi.po.VideoPO;
import com.baizhi.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 视频(Video)表控制层
 *
 * @author makejava
 * @since 2021-09-24 12:43:05
 */
@RestController
@RequestMapping("videos")
public class VideoController {
    /**
     * 服务对象
     */
    @Resource
    private VideoService videoService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;  //对字符串支持比较友好,不能存储对象

    
    @GetMapping
    public VideoPO queryAll(@RequestParam(value = "token") String token, @RequestParam("page") Integer page, @RequestParam("per_page") Integer per_page
            , @RequestParam(value = "id", required = false) Integer id, @RequestParam(value = "name", required = false) String name,
                            @RequestParam(value = "category_id", required = false) Integer category_id, @RequestParam(value = "uploader_name", required = false) String uploader_name
    ) {
        VideoPO videoPO = null;
        if (token != null) {
            HashOperations<String, Object, Object> hash = stringRedisTemplate.opsForHash();
            Boolean username = hash.hasKey(token, "username");
            System.out.println("username = " + username);
            if (username == true) {
                videoPO = videoService.PageQueryAll(page, per_page, id, name, category_id, uploader_name);
                System.out.println("videoPO = " + videoPO);
            }
        }
        return videoPO;

    }
}

